package com.mingliqiye.minecraft.enchantment.conflict.forge.mixin;

import com.mingliqiye.minecraft.enchantment.conflict.forge.ForgeMod;
import net.minecraft.world.item.enchantment.Enchantment;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Enchantment.class)
public class EnchantmentMixin {

    @Inject(method = "isCompatibleWith", at = @At("HEAD"), cancellable = true)
    private void isCompatibleWith(Enchantment enchantment, CallbackInfoReturnable<Boolean> cir) {
        var rb = ForgeMod.ENCHANTMENTCONTROLLER.canBeCombined(
            enchantment.getDescriptionId(),
            getThis().getDescriptionId()
        );
        if (rb != null) {
            cir.setReturnValue(rb);
        }
    }

    @Unique
    private Enchantment getThis() {
        return (Enchantment) (Object) this;
    }
}
